import axios from "axios";
import { userCounter } from "@/stores/counter";

const request = axios.create({
  baseURL: "http://192.168.0.112:3000",
  // baseURL: "http://127.0.0.1",
  timeout: 1000,
});

// 添加请求拦截器
request.interceptors.request.use(
  function (config) {
    let token = userCounter().token
    if(token) {
      config.headers.Authorization = 'Bearer ' + token
    }
    // 在发送请求之前做些什么
    return config;
  },
  function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  }
);

export default request
